package com.guigu.servicegoods.controller;


import com.guigu.common_util.pojo.utils.Result;
import com.guigu.servicegoods.domain.TbSku;
import com.guigu.servicegoods.service.TbSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-07-08
 */
@RestController
@RequestMapping("/servicegoods/tbsku")
public class TbSkuController {

    @Autowired
    private TbSkuService skuService;

    @PostMapping("fingPage")
    public Result findPage(@RequestBody(required = false) Map<String,Object> searchMap, Integer page, Integer size){
        return skuService.findPage(searchMap,page,size);
    }

    @PostMapping("insert")
    public Result insert(@RequestBody TbSku sku){
        if(skuService.save(sku)){
            return Result.ok();
        }
        return Result.error();
    }

    @PostMapping("update")
    public Result update(@RequestBody TbSku sku){
        if (skuService.updateById(sku)){
            return Result.ok();
        }
        return Result.error();
    }

    @GetMapping("delete")
    public Result delete(String id){
        if (skuService.removeById(id)){
            return Result.ok();
        }
        return Result.error();
    }

    @GetMapping("findById")
    public Result findById(String id){
        TbSku sku = skuService.getById(id);
        if (sku == null){
            return Result.error();
        }
        return Result.ok().data("sku",sku);
    }

}

